package utils
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.utils.Dictionary;

	public class SmallCardFactory
	{

		[Embed("../../asset/card/smallCard/bamboo1.png")]
		private static var tiao1Cls:Class;

		[Embed("../../asset/card/smallCard/bamboo2.png")]
		private static var tiao2Cls:Class;

		[Embed("../../asset/card/smallCard/bamboo3.png")]
		private static var tiao3Cls:Class;

		[Embed("../../asset/card/smallCard/bamboo4.png")]
		private static var tiao4Cls:Class;

		[Embed("../../asset/card/smallCard/bamboo5.png")]
		private static var tiao5Cls:Class;

		[Embed("../../asset/card/smallCard/bamboo6.png")]
		private static var tiao6Cls:Class;

		[Embed("../../asset/card/smallCard/bamboo7.png")]
		private static var tiao7Cls:Class;

		[Embed("../../asset/card/smallCard/bamboo8.png")]
		private static var tiao8Cls:Class;

		[Embed("../../asset/card/smallCard/bamboo9.png")]
		private static var tiao9Cls:Class;

		[Embed("../../asset/card/smallCard/circle1.png")]
		private static var tong1Cls:Class;

		[Embed("../../asset/card/smallCard/circle2.png")]
		private static var tong2Cls:Class;

		[Embed("../../asset/card/smallCard/circle3.png")]
		private static var tong3Cls:Class;

		[Embed("../../asset/card/smallCard/circle4.png")]
		private static var tong4Cls:Class;

		[Embed("../../asset/card/smallCard/circle5.png")]
		private static var tong5Cls:Class;

		[Embed("../../asset/card/smallCard/circle6.png")]
		private static var tong6Cls:Class;

		[Embed("../../asset/card/smallCard/circle7.png")]
		private static var tong7Cls:Class;

		[Embed("../../asset/card/smallCard/circle8.png")]
		private static var tong8Cls:Class;

		[Embed("../../asset/card/smallCard/circle9.png")]
		private static var tong9Cls:Class;

		[Embed("../../asset/card/smallCard/character1.png")]
		private static var wan1Cls:Class;

		[Embed("../../asset/card/smallCard/character2.png")]
		private static var wan2Cls:Class;

		[Embed("../../asset/card/smallCard/character3.png")]
		private static var wan3Cls:Class;

		[Embed("../../asset/card/smallCard/character4.png")]
		private static var wan4Cls:Class;

		[Embed("../../asset/card/smallCard/character5.png")]
		private static var wan5Cls:Class;

		[Embed("../../asset/card/smallCard/character6.png")]
		private static var wan6Cls:Class;

		[Embed("../../asset/card/smallCard/character7.png")]
		private static var wan7Cls:Class;

		[Embed("../../asset/card/smallCard/character8.png")]
		private static var wan8Cls:Class;

		[Embed("../../asset/card/smallCard/character9.png")]
		private static var wan9Cls:Class;

		[Embed("../../asset/card/smallCard/zhong.png")]
		private static var red_middlecardCls:Class;

		[Embed("../../asset/card/smallCard/fa.png")]
		private static var prosperitycardCls:Class;

		[Embed("../../asset/card/smallCard/white.png")]
		private static var white_boardcardCls:Class;

		[Embed("../../asset/card/smallCard/east.png")]
		private static var eastCardCls:Class;

		[Embed("../../asset/card/smallCard/west.png")]
		private static var westCardCls:Class;

		[Embed("../../asset/card/smallCard/south.png")]
		private static var southCardCls:Class;

		[Embed("../../asset/card/smallCard/north.png")]
		private static var northCardCls:Class;

		[Embed("../../asset/card/smallCard/wild_card.png")]
		private static var wildCardCls:Class;

		private static var normalTiaoArray:Array = [tiao1Cls, tiao2Cls, tiao3Cls, tiao4Cls, tiao5Cls, tiao6Cls, tiao7Cls, tiao8Cls, tiao9Cls];

		private static var normalTongArray:Array = [tong1Cls, tong2Cls, tong3Cls, tong4Cls, tong5Cls, tong6Cls, tong7Cls, tong8Cls, tong9Cls];

		private static var normalWanArray:Array = [wan1Cls, wan2Cls, wan3Cls, wan4Cls, wan5Cls, wan6Cls, wan7Cls, wan8Cls, wan9Cls];

		private static var cardDic:Dictionary = new Dictionary();

		public static function getNormalCardBitmapData(type:int, value:int):BitmapData
		{
			var bitmapData:BitmapData;

			if (cardDic[type + "_" + value])
			{
				bitmapData = cardDic[type + "_" + value];
			}
			else
			{
				var cls:Class = getNormalCardFrontSource(type, value);
				var bitmap:Bitmap = new cls();
				bitmapData = bitmap.bitmapData;
				cardDic[type + "_" + value] = bitmapData;
			}

			return bitmapData;
		}

		private static function getNormalCardFrontSource(type:int, value:int):Class
		{
			switch (type)
			{
				case 0:
					return normalTiaoArray[value - 1];
				case 1:
					return normalTongArray[value - 1];
				case 2:
					return normalWanArray[value - 1];
				case 3:
					return eastCardCls;
				case 4:
					return westCardCls;
				case 5:
					return southCardCls;
				case 6:
					return northCardCls;
				case 7:
					return red_middlecardCls;
				case 8:
					return white_boardcardCls;
				case 9:
					return prosperitycardCls;
				case 10:
					return wildCardCls;
				default:
					trace("cant find the front value: " + value + ", type: " + type);
					return null;
			}
		}
	}
}
